<?php
class Comment extends MY_Controller
{

    protected $__enable_login_check = false;

    public function __construct()
    {
        parent::__construct();
        $this->load->model('services/comment_service', 'comment_service');
    }

    public function createComment()
    {
        if (empty($this->_uid))
        {
            $this->renderJson(NO_LOGIN);
        }
        $create_data = [
            'novel_id'      => $this->request_array['novelId'] ?? null,
            'user_id'       => $this->_uid,
            'content'       => $this->request_array['content'] ?? null,
        ];
        $err = null;
        $res = $this->comment_service->createComment($create_data, $err);
        if ( ! is_null($err))
        {
            $this->renderJson($err['errorCode'], $err['errorMessage']);
        }
        $this->renderJson();
    }

    public function getCommentList()
    {
        $last_page = $this->request_array['page'] ?? 1;
        $novel_id = $this->request_array['novelId'] ?? null;
        $err = null;
        $result = $this->comment_service->getCommentListByNovel($novel_id, $last_page, $err);
        if ( ! is_null($err))
        {
            $this->renderJson($err['errorCode'], $err['errorMessage']);
        }
        $this->renderJson(STATUS_OK, $result);
    }
}
